package nioTest.com.io;

import java.io.FileOutputStream;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

/**
 * @author      : yang.xp
 * @date        : 2022/3/14 0014 17:35
 * @description : fileChannel 的实验案例
 */
public class NioFileChannel01 {

    public static void main(String[] args) {

        try {
            String str = "点触NB";
            FileOutputStream fileOutputStream = new FileOutputStream("./log/test.log");
            // OUTout stream 内置了一个channel
            FileChannel fileChannel = fileOutputStream.getChannel();

            ByteBuffer buffer = ByteBuffer.allocate(1024);
            // UTF-8 下 一个汉字占3个字节
            buffer.put(str.getBytes());
            buffer.flip();

            fileChannel.write(buffer);
            fileOutputStream.close();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
        }
    }
}
